<?php
namespace Home\Controller;
use Think\Controller;
use Common\Controller\CommonController;
class AttrController extends CommonController {
	//展示属性列表
	public function index(){
		$m = M('attr');
		$attr = $m->select();
		$this->assign('attr',$attr);
		$this->display();
	}
	//添加属性列表试图
	public function addattr(){
		$this->display();
	}
	//处理属性添加
	public function doaddattr(){
		if(!($_POST['name']&&$_POST['color'])){
			$this->error('请填写完整信息');
		}
		$name = I('name');
		$color = I('color');		
		$m = M('attr');
		if($m->add($_POST)){
			$this->success('添加属性成功',U('Home/Attr/index'));
		}else{
			$this->error('添加属性失败');
		}
	}
	//执行删除操作
	public function del(){
		$m = M('attr');
		$id = $_GET['id'];
		$where = array('id' => $id);
		if($m->where($where)->delete()){
			$this->success('删除成功',U('Attr/index'));
		}else{
			$this->error('删除失败',U('Attr/index'));
		}
	}
	//展示修改页面
	public function xiugai(){
		$m = M('attr');
		$id = $_GET['id'];
		$where = array('id' => $id);
		$attr = $m->where($where)->find();
		$this->assign('attr',$attr);
		$this->display();
	}
	//执行修改操作
	public function doxiugai(){
		$m = M('attr');		
		$id = $_POST['id'];
		$name = $_POST['name'];
		$color = $_POST['color'];
		$update = array(
			'id' => $id,
			'name' => $name,
			'color' => $color				
		);
		if($m->save($update)){
			$this->success('修改成功',U('Attr/index'));
		}else{
			$this->error('修改失败',U('Attr/index'));
		}
	}	
}
?>